//
//  FoundView.m
//  FVQuickMessage
//
//  Created by dllo on 16/8/9.
//  Copyright © 2016年 zty. All rights reserved.
//

#import "FoundView.h"
#import "FoundTableViewCell.h"
#import "VideoViewController.h"
#import "MQDetailVCOfFind.h"
#import "ScanViewController.h"
#import "StepViewController.h"
#import "SmileViewController.h"
#import "FamilyViewController.h"

#import "WeatherViewController.h"

@interface FoundView ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *foundTableView;

@property (nonatomic, retain) NSArray *nameArray;

@end

@implementation FoundView

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        [self creatFoundTableView];
        
    }
    return self;
}

- (void) creatFoundTableView {
    
    self.nameArray = @[@"朋友圈", /*@"扫一扫",*/ @"笑一笑", /*@"360全景",*/ @"计步器", @"地图", @"天气"];
    
    self.foundTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 35, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds) - 90)style:UITableViewStyleGrouped];
    [self addSubview:_foundTableView];
    self.foundTableView.rowHeight = self.bounds.size.height / 10;
    self.foundTableView.delegate = self;
    self.foundTableView.dataSource = self;
    [_foundTableView registerClass:[FoundTableViewCell class] forCellReuseIdentifier:@"foundTableViewCell"];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (section == 0) {
        
        return 1;
    }else {
        
        return 2;
    }
    
    return 0;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    FoundTableViewCell *foundTableViewCell  =[tableView dequeueReusableCellWithIdentifier:@"foundTableViewCell"];
    
    if (indexPath.section < 2) {
        NSString *name = [self.nameArray objectAtIndex:indexPath.section + indexPath.row];
        
        foundTableViewCell.name = name;
    } else if (indexPath.section == 2){
        NSString *name = [self.nameArray objectAtIndex:indexPath.section + indexPath.row + 1];
        
        foundTableViewCell.name = name;
    } /*else {
        NSString *name = [self.nameArray objectAtIndex:indexPath.section + indexPath.row + 2];
        
        foundTableViewCell.name = name;
    }*/
    
    return foundTableViewCell;
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 3;
    
}



-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    if (section == 0) {
        
        return 0;
    }else {
        
        return 10;
    }
    
}

//当前控制器的导航控制器
- (UINavigationController*)naviController {
    
    for (UIView* next = [self superview]; next; next = next.superview) {
        
        UIResponder* nextResponder = [next nextResponder];
        
        if ([nextResponder isKindOfClass:[UINavigationController class]]) {
            
            return (UINavigationController*)nextResponder;
        }
    }
    
    return nil;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    /*if (indexPath.section == 2 && indexPath.row == 1) {
        
        MQDetailVCOfFind *videoViewController = [[MQDetailVCOfFind alloc]init];
        
        [[self naviController] pushViewController:videoViewController animated:YES];
    }*/
    
    
    if (indexPath.section == 1 && indexPath.row == 0) {
        
        self.block();
        
        
    }
    if (indexPath.section == 2 && indexPath.row == 0) {
        self.map();
    }
    
    /*if (indexPath.section == 1 && indexPath.row == 0) {
        
        ScanViewController *scanVC = [[ScanViewController alloc] init];
        
        [[self naviController] pushViewController:scanVC animated:YES];
        
    }*/
    
    if (indexPath.section == 1 && indexPath.row == 1) {
        
        StepViewController *stepVC = [[StepViewController alloc] init];
        
        [[self naviController] pushViewController:stepVC animated:YES];
        
    }
    
    if (indexPath.section == 2 && indexPath.row == 1) {
        
      WeatherViewController *weatherVC = [[WeatherViewController alloc] init];
        
        [[self naviController] pushViewController:weatherVC animated:YES];
        
    }
    
    if (indexPath.section == 0 && indexPath.row == 0) {
        
        FamilyViewController *FVC = [[FamilyViewController alloc] init];
        
        [[self naviController] pushViewController:FVC animated:YES];
        
    }

    
}





@end
